package com.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class SendMailService {

    @Value("${spring.mail.username}")
    private String sendUsername;

    @Autowired
    private JavaMailSender javaMailSender; //发送邮件封装类

    /**
     * 无附件邮件发送
     * @param to
     * @param subject
     * @param content
     * @return
     */
    public void sendMail(String to,String subject,String content){

        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(to);//收信人
        message.setSubject(subject);//主题
        message.setText(content);//内容
        message.setFrom(sendUsername);//发信人
        javaMailSender.send(message);
    }
}
